/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.action.call;

import apus.action.Action;
import apus.action.ActionResult;
import apus.entity.Call;
import apus.persistence.CallDAO;
import apus.services.ServiceLocator;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 21vek
 */
public class CallListAction implements Action{

    @Override
    public String getName() {
        return "call.list";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        List <Call> callList = ServiceLocator.getService(CallDAO.class).findAll();
        if (request.getParameter("num_id") != null) {
            Integer num_id = Integer.parseInt(request.getParameter("num_id"));
            List<Call> tmpList = new ArrayList<Call>();
            for (Call call : callList) {
                if ((call.getNumberFrom().getId() == num_id)||(call.getNumberFrom().getId() == num_id)) {
                    tmpList.add(call);
                }
            }
            callList=tmpList;
        }
        request.setAttribute("callList", callList);
        return ActionResult.forward("/WEB-INF/View/CallView/CallListView.jsp");
    }
    
}
